package com.axonactive.yolo.webservice;

import java.io.IOException;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;

import com.axonactive.yolo.webservice.utils.Utils;

/**
 * @author pqphuong
 *
 */
@Path("/task")
public class Task {

	

	/**
	 * @param 
	 * KEY: getTaskListParam
	 * VALUE: {"userId":300,"timeStamp":"1399281563703"}
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/list")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String getTaskList(MultivaluedMap<String, String> param)
			throws IOException, InterruptedException {
		return Utils.call("get_task_list/"
				+ Utils.encode(param.getFirst("getTaskListParam")));
	}
	

	@GET
	@Path("/abc")
	@Produces(MediaType.APPLICATION_JSON)
	public String demo() throws JsonGenerationException, JsonMappingException, IOException{
		return "abc";
		
	}
	
	/**
	 * @param param
	 * KEY: deleteTaskParam
	 * VALUE: {"userId":30,"taskId":1}
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/delete")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String deleteTask(MultivaluedMap<String, String> param)
			throws IOException, InterruptedException {
		return Utils.call("delete_task/"
				+ Utils.encode(param.getFirst("deleteTaskParam")));
	}
	
	
	/**
	 * @param param
	 * KEY: saveTaskParam
	 * VALUE: {
				"userId":300,
				"taskId":0,
				"taskName":"test webservice !",
				"fromLocation":"DAD - Da Nang City, VN",
				"toLocation":"SGN - Ho Chi Minh City (Saigon), VN",
				"fromAirport":null,
				"toAirport":null,
				"fromCountry":null,
				"toCountry":null,
				"outBound":"2014/05/6",
				"inBound":"2014/05/6",
				"departDate":null,
				"returnDate":null,
				"maxPrice":"23719",
				"typeOfTrip":"roundTrip",
				"numAdult":null,
				"numChild":null,
				"numInfant":null,
				"numStop":2,
				"flexibleDays":"0",
				"airlines":"VN-Vietnam Airlines;BL-Jetstar Pacific",
				"airlineNames":null,
				"cabinClass":"0",
				"currencyCode":"USD",
				"airlinesFilterMode":null,
				"functionType":null
				}
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/save")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String saveTask(MultivaluedMap<String, String> param)
			throws IOException, InterruptedException {
		return Utils.call("save_task/"
				+ Utils.encode(param.getFirst("saveTaskParam")));
	}
	
	@POST
	@Path("/get_result")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String getTaskResult(MultivaluedMap<String, String> param)
			throws IOException, InterruptedException {
		return Utils.call("task_search/"
				+ Utils.encode(param.getFirst("getTaskResultParam")));
	}

}
